package igor.mass.model;

import com.thoughtworks.xstream.XStream;

public class SmarthouseXMLDec {
	public AndroidSmarthouse decodeXML(String xml){
		
		XStream s = new XStream();
		
		s.alias("smarthouse", AndroidSmarthouse.class);
		s.addImplicitArray(AndroidSmarthouse.class, "rooms");
		
		s.alias("room", AndroidRoom.class);
		s.useAttributeFor(AndroidRoom.class, "name");
		s.addImplicitArray(AndroidRoom.class, "devices");
		
		s.alias("device", AndroidDevice.class);
		s.useAttributeFor(AndroidDevice.class, "name");
		s.useAttributeFor(AndroidDevice.class, "description");	
		s.useAttributeFor(AndroidDevice.class, "id");
		s.addImplicitArray(AndroidDevice.class, "commands");
		
		s.alias("command", AndroidCommand.class);
		s.useAttributeFor(AndroidCommand.class, "name");
		s.useAttributeFor(AndroidCommand.class, "description");
		s.useAttributeFor(AndroidCommand.class, "id");
		s.addImplicitArray(AndroidCommand.class, "params");
		
		
		s.alias("param", AndroidParam.class);
		s.useAttributeFor(AndroidParam.class, "name");
		s.useAttributeFor(AndroidParam.class, "description");
		s.useAttributeFor(AndroidParam.class, "id");
		s.useAttributeFor(AndroidParam.class, "type");
		
		AndroidSmarthouse as =(AndroidSmarthouse) s.fromXML(xml);
		
		return as;
	}

}
